package com.fzh.wangxiao.utils;


import com.alibaba.druid.support.json.JSONUtils;

/**
 * 统一API响应结果封装
 */
public class Result<T> {
    private int code = 200;
    private String message = "SUCCESS";
    private T data;
    private Long totals;
    private Long time = System.currentTimeMillis();

    public Long getTime() {
        return time;
    }

    public void setTime(Long time) {
        this.time = time;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public Long getTotals() {
        return totals;
    }

    public void setTotals(Long totals) {
        this.totals = totals;
    }

    public Result setCode(ResultCode resultCode) {
        this.code = resultCode.code();
        return this;
    }

    public int getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

    public Result setMessage(String message) {
        this.message = message;
        return this;
    }

    public T getData() {
        return data;
    }

    public Result setData(T data) {
        this.data = data;
        return this;
    }

    @Override
    public String toString() {
        return JSONUtils.toJSONString(this);
    }
}
